﻿
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using ExtBusiness;
using ExtBusiness.Interface;

using ExtBusiness.CommonBusiness;
using ExtBusiness.FlowOperation;
using ChBusiness.CommonBusiness;

public partial class WebPubManager_SerialStateManager :PageBase
{
    private WorkFlowPubSettting wfpsTemp = new WorkFlowPubSettting();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindFlowName();
            if (Request["action"] != null && Request["iid"] != null)
            {
                //获取操作者ip地址
                string myIP = Common.IPOperation.GetIpAddress();

                string strIID = Request["iid"];
                //业务删除
                if (Request["action"] == "delete")
                {
                    wfpsTemp.SetInstanceIsDelete(strIID, "1");
                    //添加操作日志 addby zhongjian 20100331
                    //操作描述
                    string strRemark = "业务逻辑删除；受理编号为: " + strIID + " 的案件；";
                    SystemLogs.AddSystemLogs(Session["UserName"].ToString(), "update", strRemark, "",myIP);
                }
                //业务恢复
                if (Request["action"] == "Recovery")
                {
                    wfpsTemp.SetInstanceIsDelete(strIID, "0");
                    //添加操作日志 addby zhongjian 20100331
                    //操作描述
                    string strRemark = "业务逻辑恢复；受理编号为: " + strIID + " 的案件；";
                    SystemLogs.AddSystemLogs(Session["UserName"].ToString(), "update", strRemark, "",myIP);
                }
            }
            GridviewDatabind();
        }
    }

    #region 数据绑定
    /// <summary>
    /// Gridviews the databind.
    /// </summary>
    private void GridviewDatabind()
    {
        DataTable dtTemp = new DataTable();
        ViewState["flag"] = Request["flag"];
        if (ViewState["flag"] != null)
        {
            if (ViewState["flag"].ToString() == "Recovery")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "function", "<script>SetBackColor(1);</script>");//设置按钮样式
                ddlStatus.SelectedItem.Text = "已删除";
                ddlStatus.Enabled = false;
                dtTemp = wfpsTemp.GetInstance(txtIID.Text.Trim(), ddlControl.SelectedItem.Value, txtName.Text.Trim(), txtdatebegin.Value, txtdateend.Value,"");
                gridviewCar.Columns[9].Visible = true;
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "function", "<script>SetBackColor(0);</script>");//设置按钮样式
                dtTemp = wfpsTemp.GetInstance(txtIID.Text.Trim(), ddlControl.SelectedItem.Value, txtName.Text.Trim(), txtdatebegin.Value, txtdateend.Value, ddlStatus.SelectedItem.Value);
                gridviewCar.Columns[8].Visible = true;
            }
        }
        else
        {
            dtTemp = wfpsTemp.GetInstance(txtIID.Text.Trim(), ddlControl.SelectedItem.Value, txtName.Text.Trim(), txtdatebegin.Value, txtdateend.Value, ddlStatus.SelectedItem.Value);
            gridviewCar.Columns[8].Visible = true;
        }
        gridviewCar.DataSource = dtTemp;
        gridviewCar.RecordCount = dtTemp.Rows.Count;
        gridviewCar.DataBind();
    }
    #endregion 

    /// <summary>
    /// datagrid数据加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void recvgrid_OnLoadData(object sender, EventArgs e)
    {
        this.GridviewDatabind();
    }

    #region 行创建
    /// <summary>
    /// Handles the RowCreated event of the gridviewCar control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
    protected void gridviewCar_RowCreated(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.DataRow:
                //保留此删除与恢复的方法 add by zhongjian 20091223
                DataRowView drv = e.Row.DataItem as DataRowView;
                if (drv == null)
                {
                    break;
                }
                HyperLink hyDel = e.Row.FindControl("hydel") as HyperLink;
                if (hyDel != null)
                {
                    hyDel.Attributes.Add("OnClick", "return confirm('确定要删除该业务吗？')");
                    hyDel.NavigateUrl = "SerialStateManager.aspx?action=delete&flag=Remove&iid=" + drv["iid"];
                }
                HyperLink hyRec = e.Row.FindControl("hyRec") as HyperLink;
                if (hyRec != null)
                {
                    hyRec.Attributes.Add("OnClick", "return confirm('确定要恢复该业务吗？')");
                    hyRec.NavigateUrl = "SerialStateManager.aspx?action=Recovery&flag=Recovery&iid=" + drv["iid"];
                }
                break;
        }
    }
    #endregion

    /// <summary>
    /// 绑定所有流程名称
    /// </summary>
    public void BindFlowName()
    {
        DataTable dtTable = wfpsTemp.GetSelectOptions(""); 
        ddlControl.Items.Clear();
        ddlControl.Items.Add(new ListItem("请选择业务类型...",""));
        foreach (DataRow row in dtTable.Rows)
        {
            //ddlControl.Items.Add(new ListItem(row["KEYVALUE"].ToString(), row["KEYCODE"].ToString()));
            ddlControl.Items.Add(new ListItem(row["KEYVALUE"].ToString(), row["KEYVALUE"].ToString()));
        }
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        GridviewDatabind();
    }

    /// <summary>
    /// 删除业务
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <!--在行创建(gridviewCar_RowCreated)有业务删除与恢复的功能,
    /// 添加此方法是为了在操作后列表刷新而页面不刷新(保留原来的查询结果)addby zhongjian 20091224-->
    protected void lbtnDel_Click(object sender, EventArgs e)
    {
        string strIID = ((LinkButton)sender).ToolTip.ToString();
        //this.Page.ClientScript.RegisterStartupScript(this.GetType(), "ok", "<script>alert('"+strIID+"')</script>");
        wfpsTemp.SetInstanceIsDelete(strIID, "1");

        //添加操作日志 addby zhongjian 20100331
        //获取操作者ip地址
        string myIP = Common.IPOperation.GetIpAddress();
        string strRemark = "业务逻辑删除；受理编号为: " + strIID + " 的案件；";
        SystemLogs.AddSystemLogs(Session["UserName"].ToString(), "update", strRemark, "",myIP);
        this.GridviewDatabind();
    }

    /// <summary>
    /// 恢复业务
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <!--addby zhongjian 20091224-->
    protected void lbtnRec_Click(object sender, EventArgs e)
    {
        string strIID = ((LinkButton)sender).ToolTip.ToString();
        wfpsTemp.SetInstanceIsDelete(strIID, "0");

        //添加操作日志 addby zhongjian 20100331
        //获取操作者ip地址
        string myIP = Common.IPOperation.GetIpAddress();
        string strRemark = "业务逻辑恢复；受理编号为: " + strIID + " 的案件；";
        SystemLogs.AddSystemLogs(Session["UserName"].ToString(), "update", strRemark, "",myIP);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "function", "<script>SetBackColor(1);</script>");//设置按钮样式
        this.GridviewDatabind();
    }
}

